import { Route } from '@/types/common';

export function generateRoute(menuList:any){
  let routes:Route[] = []
  let actionList: string[] = []
  const deepList = (list:any) => {
    while (list.length) {
      let item = list.pop()
      if(item.level == 2){
        // 保存按钮权限
        actionList.push(item.index)
      }
      if (item.level === 1) {
        routes.push({
          name: item.component,
          path: item.index,
          meta: {
            title: item.title
          },
          component: item.component
        })
      }
      if (item.subs && item.level !== 2) {
        deepList(item.subs)
      }
    }
  }
  deepList(menuList)
  localStorage.setItem("actionList", JSON.stringify(actionList))
  return routes
}
